package com.htc.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;


public class CommonUtils {
	
	public static String getUUID() {
		String uuid = UUID.randomUUID().toString().replace("-", "");
		return uuid;
	}

	public static String getNowTime() {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return df.format(new Date()).toString();
	}
	
	 public static int calculateTimeDifferenceByCalendar(String strDate,String endDate) throws ParseException{
	      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	      Date date1 = formatter.parse(strDate);
	      Date date2 = formatter.parse(endDate);
	  
	     Calendar c1 = Calendar.getInstance();   //当前日期
	     Calendar c2 = Calendar.getInstance();
	     c1.setTime(date1);
	     c2.setTime(date2);
	     
	     int hour1 = c1.get(Calendar.HOUR);
	     int hour2 = c2.get(Calendar.HOUR);
	     int date = c2.get(Calendar.DATE)-c1.get(Calendar.DATE);
	     return (hour2 - hour1)+(date*24);
	 }
	 
	 public static void main(String[]arg) {
		try {
			int hour = calculateTimeDifferenceByCalendar("2019-12-04 00:00:00","2019-12-05 00:00:00");
			System.out.print(hour);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
	 }
	
}
